#include "GHANeuron.h"

#include "../Utils/RandomUtil.h"

CGHANeuron::CGHANeuron(int InputDimension) :
	m_W(InputDimension),
	m_LW(InputDimension),
	m_X(InputDimension)
{
	
	for (int i = 0; i < this->m_W.GetDimesion(); i++)
	{
		this->m_W[i] = (::rand() * 1.0 / RAND_MAX) * 0.001;
	}

	for (int i = 0; i < this->m_LW.GetDimesion(); i++)
	{
		this->m_LW[i] = this->m_W[i] * -10.0;
	}
}

double CGHANeuron::Execute(const Vector2 & Input)
{
	this->m_X = Input;

	this->m_Y = this->m_W.Dot(this->m_X);
			
	return this->m_Y;
}

Vector2 & CGHANeuron::GetWeightVector()
{
	return this->m_W;
}

void CGHANeuron::SetWeightVector(const Vector2 & newW)
{
	this->m_LW = this->m_W;
	this->m_W = newW;
}

Vector2 & CGHANeuron::GetInputVector()
{
	return this->m_X;
}

double CGHANeuron::GetOutputValue()
{
	return this->m_Y;
}

bool CGHANeuron::CheckWChangeRate(double EPS)
{
	for (int i = 0; i < this->m_W.GetDimesion(); i++)
	{
		if (::fabs(this->m_W.GetVectorElement(i) - this->m_LW.GetVectorElement(i)) > EPS)
		{
			return false;
		}
	}

	return true;
}